home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
prolog
/
sbprolog
/
amiga
/
c_src2_5.zoo
/
sub_inst.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-08-16
|
4KB
|
158 lines
/************************************************************************
* *
* The SB-Prolog System *
* Copyright SUNY at Stony Brook, 1986; University of Arizona, 1987 *
* *
************************************************************************/
/*-----------------------------------------------------------------
SB-Prolog is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY. No author or distributor
accepts responsibility to anyone for the consequences of using it
or for whether it serves any particular purpose or works at all,
unless he says so in writing. Refer to the SB-Prolog General Public
License for full details.
Everyone is granted permission to copy, modify and redistribute
SB-Prolog, but only under the conditions described in the
SB-Prolog General Public License. A copy of this license is
supposed to have been given to you along with SB-Prolog so you
can know your rights and responsibilities. It should be in a
file named COPYING. Among other things, the copyright notice
and this notice must be preserved on all copies.
------------------------------------------------------------------ */
/* sub_inst.c */
/* modification history
07/16/89 RNK - Modified signals for Amiga,
added flag AMIGA, define it for amiga port
RNK = Nick Kline
*/
#include <signal.h>
#include "sim.h"
#include "aux.h"
#ifndef AMIGA
struct sigvec vec;
#endif
/* set interrupt code in reg 2 and return ep of interrupt handler */
byte *set_intercode(intcode)
int intcode;
{
if (!is_PRED(interrupt_psc)) {
quit("Interrupt handler not defined\n");
}
gregc(2) = makeint(intcode);
return(get_ep(interrupt_psc));
}
intercept_proc()
{
if (interrupt_code == 0) {
interrupt_code = 1;
}
else exit(2);
}
arm_intercept()
{
/* set up interrupt routine */
#ifdef AMIGA
signal(SIGINT,intercept_proc); /* branch on ^C */
#else
vec.sv_handler = intercept_proc;
vec.sv_mask = 0;
vec.sv_onstack = 0;
sigvec(2, &vec, 0);
#endif
}
/****************************************************************************/
callv_sub() /* arg from register 1 */
{
word term;
register pw top;
short int i;
struct psc_rec *psc_ptr;
char s1[256];
term = gregc(1);
cvlab: switch ((int)(term & TAGMASK)) {
case FREE:
nderef (term, cvlab);
case NUM:
printf("illegal call\n");
Fail0;
return;
case LIST:
psc_ptr = list_psc;
term -= 4;
goto cstst;
case CS:
psc_ptr = get_str_psc(term);
cstst:
if (interrupt_code > 0)
{ interrupt_code = 0;
pcreg = set_intercode(1);
return;
};
/* call code */
if (is_PRED(psc_ptr) || is_DYNA(psc_ptr))
pcreg = get_ep(psc_ptr);
else
{ pcreg = set_intercode(0);
return;
}
untag(term);
for (i = 1; i <= get_arity(psc_ptr); ++i)
gregc(i) = follow((pw) term + i);
}
if (hitrace == 1)
{ printf("callv: ");
writepname(stdout, get_name(psc_ptr), get_length(psc_ptr));
printf(" (");
for (i = 1; i <= get_arity(psc_ptr); i++)
{ printf(" ");
printterm(gregc(i), 1);
}
printf(")\n");
}
}
/****************************************************************************/
/* builds the current call onto the heap and points reg 1 to it,
and puts the interrupt number in reg 2 */
build_call(psc)
struct psc_rec *psc;
{
register word callstr, arg;
register int i;
register pw top;
callstr = (word)hreg; /* save addr of new structure rec */
new_heap_node((word)psc); /* set str psc ptr */
for ( i=1; i<=get_arity(psc); i++) {
arg = gregc(i);
bldc: if ((arg & 3) == 0) {
nderef(arg, bldc);
follow(arg) = (word)hreg;
pushtrail(arg);
new_heap_free;
}
else new_heap_node(arg);
}
gregc(1) = callstr | CS_TAG; /* ptr to new structure on heap */
}